package timing.ukulele.seal.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import timing.ukulele.seal.persistent.Seal;
import timing.ukulele.seal.service.SealService;

import javax.servlet.http.HttpServletResponse;

@Slf4j
@Controller
@RequestMapping("/seal")
public class SealResourceController {
    private final SealService service;

    public SealResourceController(SealService service) {
        this.service = service;
    }

    /**
     * 获取印章图片，此接口是开放权限的，因此返回的是含水印的印章图片
     *
     * @param id
     * @param response
     */
    @GetMapping("/sealFile")
    public void getSealFile(@RequestParam("id") Long id, HttpServletResponse response) {
        Seal seal = this.service.getById(id);
        if (seal != null && StringUtils.hasText(seal.getSealFile()))
            this.service.getSeal(seal, response);
    }

}
